/*! \file rpn_stack.h
 *  \brief Reverse Polish Notation (RPN) stack structure
 *  \author Lluis Garrido
 *
 *  This file contains the structures necessary for
 *  storing the reverse polish notation of an arbitrary
 *  expression.
 */

#ifndef RPN_STACK_H
#define RPN_STACK_H

/*! \def RPN_TYPE_NONE 
 *  \brief Valid value for type_item in rpn_stack_item. Indicates that no element is stored in the structure. 
 */ 
#define RPN_TYPE_NONE          0
/*! \def RPN_TYPE_NUMBER
 *  \brief Valid value for type_item in rpn_stack_item. Indicates that a numerical value is stored in the structure. 
 */ 
#define RPN_TYPE_NUMBER        1
/*! \def RPN_TYPE_FUNCTION
 *  \brief Valid value for type_item in rpn_stack_item. Indicates that a function identifier is stored in the structure. 
 */ 
#define RPN_TYPE_FUNCTION      2
/*! \def RPN_TYPE_VARIABLE
 *  \brief Valid value for type_item in rpn_stack_item. Indicates that a variable identifier is stored in the structure. 
 */ 
#define RPN_TYPE_VARIABLE      3
/*! \def RPN_TYPE_OPERATOR
 *  \brief Valid value for type_item in rpn_stack_item. Indicates that an operator identifier is stored in the structure. 
 */ 
#define RPN_TYPE_OPERATOR      4
/*! \def RPN_TYPE_LPARENTHESIS
 *  \brief Valid value for type_item in rpn_stack_item. Indicates that a left parenthesis is stored in the structure. 
 */ 
#define RPN_TYPE_LPARENTHESIS  5

/*! \struct rpn_stack_item
 *  \brief Reverse Polish Notation Stack Element 
 *
 *  This structure is the basic item of the  
 *  stack.
 *  
 */

struct rpn_stack_item
{
  int type_item;  /*!< The type of the item: may be RPN_TYPE_NONE, RPN_TYPE_NUMBER,
                       RPN_TYPE_FUNCTION, RPN_TYPE_VARIABLE, RPN_TYPE_OPERATOR or
		       RPN_TYPE_LPARENTHESIS. */

  /*! \union item
   *  \brief The value or identifier associated to type_item. 
   *
   *  The value or identifier associated to type_item. An annonymous
   *  union could have been used here but doxygen is currently not
   *  able to parse them correctly.
   *
   */

  union item 
  {
    double number;   /*!< If type_item is RPN_TYPE_NUMBER, this member stores it's value */ 
    int operator_id; /*!< If type_item is RPN_TYPE_OPERATOR, this member stores it's id */
    int function_id; /*!< If type_item is RPN_TYPE_FUNCTION, this member stores it's id */
    int variable_id; /*!< If type_item is RPN_TYPE_VARIABLE, this member stores it's id */
  } value; /*!< The value or identifier associated to type_item */
};

/*! \struct rpn_stack
 *  \brief Reverse Polish Stack
 *
 *  This structure is used as a stack in order to transform 
 *  an expression with infix notation to an expression with
 *  postfix notation. This structure is an array of
 *  rpn_stack_item.
 */

struct rpn_stack
{
  int currel;     /*!< The index to the first free element on top of the stack. */
  int nitems;  /*!< The number of rpn_stack_items it can hold */
  struct rpn_stack_item *el; /*!< The array of rpn_stack_item */  
};

#endif
